package cn.gson.crm.controller.studentdetail;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.StudentDetailDao;
import cn.gson.crm.model.entity.StudentDetail;

/**
 * Servlet implementation class SingerPayRecord
 */
@WebServlet("/payRecord")
public class PayRecord extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private StudentDetailDao singerpayrecordDao = new  StudentDetailDao();    
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String stuId = request.getParameter("stuId");
		String id = request.getParameter("id");
		String p = request.getParameter("page");
		Date payDate = null ;
		if (request.getParameter("payDate")!= null) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			payDate = sdf.parse(request.getParameter("payDate"));
			System.out.println(payDate);
		}
			
		if (p == null ||  p.isEmpty()) {
			p = "1";			
		}
		Integer page = Integer.parseInt(p);
		
		List<StudentDetail> singerpayrecordList = singerpayrecordDao.getPayList(page, stuId,payDate);
		StudentDetail singerpayrecord = singerpayrecordDao.getPayRecord(id);
		int totalPage = singerpayrecordDao.getPayTotalPage(stuId,payDate);
		request.setAttribute("queryString", noPageQueryString(request));
		request.setAttribute("singerpayrecordList", singerpayrecordList);
		request.setAttribute("singerpayrecord", singerpayrecord);
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("page",page);
		forward("student/singerpayrecord.jsp");
		}

}
